package Server.DataBase;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
 *implement all PreCourse query handler
 */
public class PreCourseQuery extends Query {
	/**
	* constructor parent query
	 */
	public PreCourseQuery(){
		super();
	}
	/**
	 * method set a course precourse
	 * @param pre
	 * @param post
	 * @throws SQLException
	 */
	public void addPreCourse(int pre, int post) throws SQLException{
		setQuery("INSERT INTO precourse(pre, post) VALUES(?,?)");
		PreparedStatement query = getPS();
		query.setInt(1, pre);
		query.setInt(2, post);
		query.executeUpdate();
		query.close();
	}
	/**
	 * getPreCourse
	 * @param idCourse
	 * @return array of precourse
	 * @throws SQLException
	 */
	public ArrayList<Course> getPreCourse(int idCourse) throws SQLException{
		ArrayList<Course> array = new ArrayList<Course>();
		setQuery("SELECT * FROM precourse WHERE post='"+idCourse+"'");
		ResultSet rs = execQuery();
		while (rs.next()){
			array.add(new CourseQuery().getCourseById(rs.getInt(1)));
		}
		return array;
	}

}
